<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="企业名称" prop="bodyName">
        <el-input v-model="queryParams.bodyName" placeholder="请输入企业名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>

      <!-- <el-form-item label="认证状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择认证状态" clearable>
          <el-option v-for="dict in dict.type.sys_authinfo_status" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item> -->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">

      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['article:info:remove']">删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['article:info:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="infoList" @selection-change="handleSelectionChange">


      <el-table-column type="selection" width="55" align="center" />
      <el-table-column type="index" width="50" align="center" label="序号" />
      <el-table-column label="企业名称" align="center" prop="bodyName" />
      <el-table-column label="企业地址" align="center" prop="businessAddress" width="180" />
      <el-table-column label="统一信用代码" align="center" prop="unifyCreditCode" width="180" />
      <!-- <el-table-column label="营业执照" align="center" prop="businessLicense" width="100">
        <template slot-scope="scope">
          <image-preview :src="scope.row.businessLicense" :width="50" :height="50" />
        </template>
</el-table-column> -->


      <el-table-column label="所属角色" align="center" prop="roleName" />

      <el-table-column label="用户账号" align="center" prop="phone" width="120" />

      <el-table-column label="所属行业" align="center" prop="industry" />

      <!-- <el-table-column label="认证状态" align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_authinfo_status" :value="scope.row.status" />
        </template>
      </el-table-column> -->
      <!-- <el-table-column label="驳回原因" align="center" prop="rejectionReasons" /> -->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['article:info:edit']">评分</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['article:info:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改用户认证管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1000px" append-to-body>
      <el-form v-if="form" ref="form" :model="form" :rules="rules" label-width="180px">

        <el-form-item label="企业名称" prop="bodyName">

          <el-input v-model="form.bodyName" placeholder="请输入企业名称" disabled />
        </el-form-item>
        <el-form-item label="统一信用代码" prop="unifyCreditCode">

          <el-input v-model="form.unifyCreditCode" placeholder="请输入企业名称" disabled />
        </el-form-item>
        <!-- <el-form-item label="企业地址" prop="businessAddress">
          <el-input v-model="form.businessAddress" type="textarea" placeholder="请输入内容" disabled />
        </el-form-item> -->

        <el-form-item label="所属行业" prop="industry">
          <el-input v-model="form.industry" placeholder="请输入所属行业" disabled />
        </el-form-item>
        <el-form-item label="营业执照" prop="businessLicense">
          <!-- <image-upload v-model="form.businessLicense" disabled :showTip2="shouldShowTip" /> -->

          <image-preview :src="form.businessLicense" :width="200" :height="100" />

        </el-form-item>

        <el-form-item label="其他资料:" prop="material">
          <el-upload class="upload-demo" :file-list="fileList" :on-preview="handlePreview" action :disabled="true"
            ref="upload">
          </el-upload>
          <el-dialog :visible.sync="dialogVisible" title="预览" width="800" append-to-body>
            <img style="display: block; max-width: 100%; margin: 0 auto" :src="httpurl + dialogImageUrl">
          </el-dialog>
        </el-form-item>

        <!-- 基础评分项 -->
        <el-form-item label="价格鉴证评估机构负责人分" prop="functionaryScore">
          <el-input-number v-model="form.functionaryScore" placeholder="请输入负责人执业资格分数" @change="handleChange" />
        </el-form-item>
        <el-form-item label="注册价格鉴证师数量分" prop="forensicExpertScore">
          <el-input-number v-model="form.forensicExpertScore" placeholder="注册价格鉴证师人数≥4人得8分" @change="handleChange" />
        </el-form-item>
        <el-form-item label="价格评估机构管理制度分" prop="managerScore">
          <el-input-number v-model="form.managerScore" placeholder="请输入管理制度评分" @change="handleChange" />
        </el-form-item>
        <el-form-item label="查验资质等级与会员级别分" prop="levelScore">
          <el-input-number v-model="form.levelScore" placeholder="甲级6分/乙级4分" @change="handleChange" />
        </el-form-item>
        <el-form-item label="近三年获奖/表彰分" prop="commendScore">
          <el-input-number v-model="form.commendScore" placeholder="请输入获奖表彰分数" @change="handleChange" />
        </el-form-item>
        <el-form-item label="机构及人员不规范行为分" prop="nonstandardScore">
          <el-input-number v-model="form.nonstandardScore" placeholder="请输入不规范行为扣分" @change="handleChange" />
        </el-form-item>
        <!-- <el-form-item label="基础项最终得分" prop="basicFinalScore">
          <el-input-number v-model="form.basicFinalScore" placeholder="请输入基础项最终得分" />
        </el-form-item> -->
        <!-- 审计评分项 -->
        <el-form-item label="审计报告分" prop="auditReportScore">
          <el-input-number v-model="form.auditReportScore" placeholder="年收入100万及以上得10分，年收入50万得8分"
            @change="handleChange" />
        </el-form-item>
        <el-form-item label="重要文件分" prop="importantDocumentScore">
          <el-input-number v-model="form.importantDocumentScore" placeholder="请输入重要文件评分" @change="handleChange" />
        </el-form-item>
        <el-form-item label="评估依据分" prop="evaluationBasisScore">
          <el-input-number v-model="form.evaluationBasisScore" placeholder="请输入评估依据评分" @change="handleChange" />
        </el-form-item>
        <el-form-item label="内容描述分" prop="contentDescriptionSocre">
          <el-input-number v-model="form.contentDescriptionScore" placeholder="请输入内容描述评分" @change="handleChange" />
        </el-form-item>
        <el-form-item label="文书用语分" prop="wordPaperScore">
          <el-input-number v-model="form.wordPaperScore" placeholder="请输入文书用语评分" @change="handleChange" />
        </el-form-item>
        <el-form-item label="签字盖章分" prop="signScore">
          <el-input-number v-model="form.signScore" placeholder="请输入签字盖章评分" @change="handleChange" />
        </el-form-item>
        <!-- <el-form-item label="质量评价最终得分" prop="qualityFinalScore">
          <el-input-number v-model="form.qualityFinalScore" placeholder="请输入质量评价最终得分" />
        </el-form-item> -->
        <!-- 人员要求评分项 -->
        <el-form-item label="人员要求分" prop="personnelRequirementScore">
          <el-input-number v-model="form.personnelRequirementScore" :min="0" @change="handleChange" />
        </el-form-item>
        <el-form-item label="资质要求分" prop="qualificationrequirementScore">
          <el-input-number v-model="form.qualificationrequirementScore" :min="0" @change="handleChange" />
        </el-form-item>
        <el-form-item label="成功案例分" prop="successfulCaseScore">
          <el-input-number v-model="form.successfulCaseScore" placeholder="请输入成功案例评分" @change="handleChange" />
        </el-form-item>
        <el-form-item label="自身数改分" prop="selfNumberModificationScore">
          <el-input-number v-model="form.selfNumberModificationScore" placeholder="请输入自身数改评分" @change="handleChange" />
        </el-form-item>
        <el-form-item label="其他相关分" prop="otherRelatedScore">
          <el-input-number v-model="form.otherRelatedScore" placeholder="请输入其他相关评分" @change="handleChange" />
        </el-form-item>
        <el-form-item label="最终得分" prop="finalScore">
          <el-input-number v-model="form.finalScore" placeholder="请输入要素最终得分" @change="handleChange" disabled />
        </el-form-item>

      </el-form>



      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listInfo, getInfo, delInfo, addInfo, updateInfo } from "@/api/score/score";

export default {
  name: "Info",
  dicts: ['sys_islong_or_short', 'sys_corporate_id_type', 'sys_authinfo_status', 'sys_funding_round'],
  data() {
    return {
      fileList: [],
      shouldShowTip: false,
      // 遮罩层
      loading: true,
      // 选中数组
      sids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用户认证管理表格数据
      infoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        corporateName: null,
        managerName: null,
        industry: null,
        status: null,
        bodyName: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {

        businessLicense: [
          { required: true, message: "营业执照不能为空", trigger: "blur" }
        ],
        businessScope: [
          { required: true, message: "经营范围不能为空", trigger: "blur" }
        ],
        businessAddress: [
          { required: true, message: "企业地址不能为空", trigger: "blur" }
        ],
        businessPeriodStart: [
          { required: true, message: "营业期限(开始)不能为空", trigger: "blur" }
        ],


        managerLetter: [
          { required: true, message: "账号管理人授权书不能为空", trigger: "blur" }
        ],

        industry: [
          { required: true, message: "所属行业不能为空", trigger: "blur" }
        ],
        fundingRound: [
          { required: true, message: "股权融资情况不能为空", trigger: "blur" }
        ],
        status: [
          { required: true, message: "认证状态不能为空", trigger: "change" }
        ],
        evaluationBasisScore: [
          { required: true, message: '请输入评估依据评分', trigger: 'blur' }
        ],
        contentDescriptionScore: [
          { required: true, message: '请输入内容描述评分', trigger: 'blur' }
        ]
      }

      ,
      type: "",
      dialogImageUrl: "",
      httpurl: 'http://1.94.210.234:8080/',
      dialogVisible: false
    };
  },
  created() {
    this.getList();
  },
  methods: {


    // 如果需要手动清空文件列表
    clearFiles() {
      this.fileList = [];
      if (this.$refs.upload) {
        this.$refs.upload.clearFiles();
      }
    },
    //点击文件事件
    handlePreview(file) {
      // console.log(file)
      this.type = file.type
      if (file.url != null) {
        if (file.type == '.pdf') {
          // this.dialogImageUrl = file.url
          // this.dialogVisible = true
          // this.type = file.type
          window.open(this.httpurl + file.url, '_blank')
        } else {
          this.dialogImageUrl = file.url
          this.dialogVisible = true
        }
      } else {
        if (file.raw.type == 'application/pdf') {
          window.open(this.httpurl + file.response.data, '_blank')
        } else {
          this.dialogImageUrl = file.response.data
          this.dialogVisible = true
        }
      }
    },
    handleChange(currentValue, oldValue) {
      console.log(currentValue, oldValue);
      this.form.finalScore += (currentValue - oldValue);
    },
    /** 查询用户认证管理列表 */
    getList() {
      this.loading = true;
      listInfo(this.queryParams).then(response => {
        this.infoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        userId: null,
        roleId: null,
        businessLicense: null,
        businessScope: null,
        businessAddress: null,
        businessPeriodStart: null,
        businessPeriodEnd: null,
        businessPeriodLong: null,
        corporateName: null,
        managerName: null,
        managerEmail: null,
        managerLetter: null,
        capital: null,
        industry: null,
        fundingRound: null,
        mainDescription: null,
        dataDescription: null,
        introduce: null,
        performance: null,
        status: null,
        rejectionReasons: null,
        bodyName: null,
        unifyCreditCode: null,


      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.sids = selection.map(item => item.sid)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加用户认证管理";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {

      const id = row.id || this.ids;
      getInfo(id).then(response => {
        this.form = response.data;
        console.log(this.form);
        if (this.form.material != null) {
          console.log("进入了");
          this.form.material = this.form.material.split(',')
          console.log(this.form.material);
          this.fileList = this.form.material.map(url => {
            const index = url.lastIndexOf('/')
            const name = url.substring(index + 1)
            const type = url.slice(-4)
            return { name, url, type }
          })
          this.form.material = this.form.material.toString();
        } else {

          this.clearFiles();
        }


        // console.log("fileList", this.fileList);
        this.open = true;
        this.title = "修改用户认证管理";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateInfo(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addInfo(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const sids = row.id || this.sids;
      this.$modal.confirm('是否确认删除用户认证管理编号为"' + sids + '"的数据项？').then(function () {
        return delInfo(sids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('article/info/export', {
        ...this.queryParams
      }, `info_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
<style scoped>
/* 如果你需要在组件内部定义样式 */
.text-ellipsis {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
</style>